import { createApp } from 'vue'

/*element相关*/
import ElementPlus, {ElMessage} from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import '@icon-park/vue-next/styles/index.css';

import {install} from '@icon-park/vue-next/es/all';

import App from './App.vue'
import router from './router'
import mitt from "mitt"
//自定论
import util from "./sysConfig/util.js";

const app = createApp(App)
app.config.globalProperties.$mybus = mitt()//兄弟組件傳值

install(app, 'i'); // use custom prefix 'i', eg: icon is People, name is i-people.
/*窗口自動放大縮小*/
util.zoom();
window.onresize = () => {
    util.zoom();
};

app.use(router).use(ElementPlus)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.mount('#app')
router.beforeEach((to,from,next)=>{
    if(to.meta.requireAuth){
        if(sessionStorage.getItem('userId')){//未登陸直接訪問頁面內容，則跳轉到登陸頁


            next();


        }
        else{
            if(to.path==='/'){
                next();
            }
            else{
                //alert("請登錄！")
                ElMessage({message:"未登陸，請先登陸！",type:"error"})
                next({
                    path:'/'
                })
            }

        }
        document.title="当前用户"+sessionStorage.getItem("userId");
    }
    else{
        next();
    }
})